<?php
//This Code is published under the conditions of the CDDL (Sun Microsystems) (c) 2008 by Fabian Tschirschnitz	
	class SalsaDrawer{
		//erzeugt ein Dotplot in SVG aus einer übergebenen Matrix, $zoom gibt die SVG-Skalierung an
		function draw_dotplot($dotplot, $zoom=3){
			$maxa = sizeof($dotplot);
			$maxb = sizeof($dotplot[0]);
			
			for ($i=0;$i<sizeof($dotplot);$i++){
                for ($j=0;$j<sizeof($dotplot[0]);$j++){
                        	if($dotplot[$i][$j]==1){ 
                        		  $zi=($i+1)*$zoom;
                        		  $zj=($j+1)*$zoom;
                        		  $pointsize=$zoom/2.25;
                                $string .= "<circle cx ='{$zi}' cy ='{$zj}' r ='{$pointsize}' fill='#287795' stroke='#282828'/>";}      
                }
        }   
     
       $maxa=($maxa+1)*$zoom;
       $maxb=($maxb+1)*$zoom;
      

       $r=rand(1,1024);
       $filedirectory = "../";
	    $filename = "images/dotplots/dotplot{$r}.svg";
	   	$filecontent=
	    "<?xml version='1.0' encoding='utf-8'?>

	    <svg xmlns='http://www.w3.org/2000/svg'
  	    xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:ev='http://www.w3.org/2001/xml-events'
 	    version='1.1' baseProfile='full'
	    width='{$maxa}' height='{$maxb}'>
	    <rect x='0' y='0' width='{$maxa}' height='{$maxb}' fill='#EFEFDF' stroke='none'/>
		 <content>
		 </svg>"
		 ;
		
		 $filecontent=str_replace("<content>", $string, $filecontent);
	
		 $fhandle = fopen($filedirectory.$filename, "w+");
		 fwrite($fhandle, $filecontent);
		 fclose($fhandle);
		 
		 echo "<object data='{$filename}' type='image/svg+xml' width='480' height='{$maxb}'><a href='{$filename}'><b>Grafik</b></a></object>";		
		} 
	
	}
?>